package fun.barryhome.ebean.model;

import io.ebean.Model;
import io.ebean.annotation.WhenCreated;
import io.ebean.annotation.WhenModified;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import java.time.Instant;

/**
 * Base domain object with Id, version, whenCreated and whenModified.
 *
 * <p>
 * Extending Model to enable the 'active record' style.
 *
 * <p>
 * whenCreated and whenModified are generally useful for maintaining external search services (like
 * elasticsearch) and audit.
 */
@AllArgsConstructor
@NoArgsConstructor
@MappedSuperclass
public abstract class BaseModel extends Model {

  @Id
  long id;

  @Version
  Long version;

  @WhenCreated
  Instant whenCreated;

  @WhenModified
  Instant whenModified;

}
